/*
 * @Author: boyyang
 * @Date: 2022-01-31 11:41:09
 * @LastEditTime: 2022-01-31 13:06:03
 * @LastEditors: boyyang
 * @Description: 
 * @FilePath: \boyyang\plugin\vite.config.ts
 */

import { ConfigEnv, defineConfig, UserConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'

const path = require('path')

// https://vitejs.dev/config/
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
    const root = process.cwd()
    const env = loadEnv(mode, root)
    return {
        base: './',
        plugins: [
            vue()
        ],

        build: {
            assetsDir: 'assets',
            target: "es2019",
            brotliSize: false,
            chunkSizeWarningLimit: 2000,
            lib: {
                entry: path.resolve(__dirname, 'index.ts'),
                name: 'boyyangUi',
                fileName: (format) => `boyyang.${format}.js`
            },
            rollupOptions: {
                // 确保外部化处理那些你不想打包进库的依赖
                external: ['vue'],
                output: {
                    // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
                    globals: {
                        vue: 'Vue'
                    }
                }
            }
        }
    }
})

